import request from '@/utils/request'
import type { CityResponseData, Patient, PatientAll } from './type'

enum API {
  // 获取全部就诊人信息的接口地址
  HOSPITAL_PATIENT_URL = '/user/patient/auth/findAll',
  // 获取省市区的接口地址
  CITY_URL = '/cmn/dict/findByParentId/',
  // 新增就诊人的接口地址
  ADD_PATIENT_URL = '/user/patient/auth/save',
  // 修改已有就诊人的接口地址
  UPDATE_PATIENT_URL = '/user/patient/auth/update',
  // 删除已有就诊人的接口地址
  DELETE_PATIENT_URL = '/user/patient/auth/remove/',
}

// 获取全部就诊人接口的方法
export const reqAllPatient = () =>
  request.get<any, PatientAll>(API.HOSPITAL_PATIENT_URL)
// 获取城市的接口方法
export const reqCity = (cityId: string) =>
  request.get<any, CityResponseData>(API.CITY_URL + cityId)
// 新增就诊人的接口方法(无id)
export const reqAddOrUpdatePatient = (patientData: Patient) => {
  // 根据收集的数据是否有id判断为更新还是新增
  if (patientData.id) {
    // 更新
    return request.put<any, any>(API.UPDATE_PATIENT_URL, patientData)
  } else {
    // 新增
    return request.post<any, any>(API.ADD_PATIENT_URL, patientData)
  }
}
// 删除就诊人的接口方法
export const reqDeletePatient = (id: number) =>
  request.delete<any, any>(API.DELETE_PATIENT_URL + id)
